package com.tencent.mapper;

import com.tencent.entity.CheckGroup;
import com.tencent.entity.Checkitem;
import com.tencent.entity.Result;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

public interface CheckGroupMapper {

    /**
     * 查询检查组所有
     * @return
     */
//    @Select("select * from t_checkgroup")
    public List<CheckGroup> findAll(String str);
    /**
     * 新增检查组
     * @param checkGroup
     * @return
     */
    @Insert("insert into t_checkgroup values (#{id},#{code},#{name},#{helpCode},#{sex},#{remark},#{attention})")
    @Options(useGeneratedKeys = true, keyColumn = "id",keyProperty = "id")
    public int insert(@RequestBody CheckGroup checkGroup);

    /**
     * 根据检查组id进行删除
     * @param id
     * @return
     */
    @Delete("delete from t_checkgroup where id =#{id}")
    public int deleteByCode(String id);

    /**
     * 根据检查组id进行查询
     * @param id
     * @return
     */
    @Select("select * from t_checkgroup where id = #{id}")
    public CheckGroup findById(Integer id);

    /**
     * 根据id修改检查组信息
     * @param checkGroup
     * @return
     */
    @Update("update t_checkgroup set code = #{code},name = #{name},helpCode = #{helpCode}, sex = #{sex}, remark = #{remark}, attention = #{attention} where id = #{id}")
    public int updateById(CheckGroup checkGroup);

    /**
     * 根据检查组id查询对应检查项
     * @param id
     * @return
     */
    @Select("SELECT t_checkitem.id,t_checkitem.`code`,t_checkitem.`name`,t_checkitem.remark FROM  t_checkgroup JOIN t_checkitem JOIN t_checkgroup_checkitem WHERE\n" +
            "t_checkgroup.id = t_checkgroup_checkitem.checkgroup_id and \n" +
            "t_checkitem.id = t_checkgroup_checkitem.checkitem_id AND\n" +
            "t_checkgroup.id = #{checkGroupId}")
    public List<Checkitem> findChecks(Integer id);

    @Select("select * from t_checkitem")
    public List<Checkitem> findAddChecks();

    @Insert("insert into t_checkgroup_checkitem values (#{groupId},#{itemId})")
    public int insertChecks(@Param("groupId") Integer groupId,@Param("itemId") Integer itemId);
}
